﻿using System.Net.NetworkInformation;

namespace EnvCheck.Models;
public enum VersionMatchPolicy
{
    None,
    GreaterThan,
    Equal,
    GreaterThanOrEqual
}
public class AppVersionRequirement
{
    public static Dictionary<string, VersionMatchPolicy> VersionPolicyEnumsDisplays { get; } = new()
    {
        { "不检测",VersionMatchPolicy.None  },
        { "相等",VersionMatchPolicy.Equal  },
        { "高于" ,VersionMatchPolicy.GreaterThan },
        { "不低于",VersionMatchPolicy.GreaterThanOrEqual  }
    };



    public string Name { get; set; } = string.Empty;

    public string ExpectedVersion { get; set; }
    public bool Required { get; set; } = true;

    public VersionMatchPolicy VersionPolicyValue { get; set; } = VersionMatchPolicy.GreaterThanOrEqual;

    public string VersionPolicyDisplay
    {
        get
        {
            return VersionPolicyEnumsDisplays
            .FirstOrDefault(kv => kv.Value == VersionPolicyValue).Key
                ?? VersionPolicyValue.ToString();
        }
        set
        {
            if (Enum.TryParse(value, out VersionMatchPolicy policy))
            {
                VersionPolicyValue = policy;
            }
        }
    }

    public override string ToString()
    {
        return $"\t{Name}\n\tVersion: {ExpectedVersion}";
    }

}
